package com.atde._05_behavioral_design_patterns.interpreter;


import java.util.HashMap;

/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._05_behavioral_design_patterns.interpreter
 * @Author: Del
 * @CreateTime: 2025-06-30  09:24
 * @Description: 解释器模式：
 * @Version: 1.0
 */
public class AddExpression extends SymbolExpression{

    public AddExpression(Expression left, Expression right) {
        super(left, right);
    }

    // 处理相加
    // 它所调用的是 varExpression 的 interpret 方法获取对应的值
    public int interpret(HashMap<String, Integer> var) {
        // super.left.interpret(var)：它返回 left 表达式对应的值
        // super.right.interpret(var)：它返回 right 表达式对应的值
        return super.left.interpret(var) + super.right.interpret(var);
    }
}
